/**
 * ManUndoableEdit.java
 * 21/05/2011 09:36:29
 */
package model.memento;

import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;

import model.pieces.Man;
import model.pieces.Piece;

/**
 * @author walber
 *
 */
public class ManUndoableEdit extends PieceUndoableEdit {

	private static final long serialVersionUID = 2507085559531110523L;

	/**
	 * @param piece
	 * @param direction
	 */
	public ManUndoableEdit(Piece piece, MovementDirection direction) {
		super(piece, direction);
	}

	/**
	 * @see model.memento.PieceUndoableEdit#undo()
	 */
	@Override
	public void undo() throws CannotUndoException {
		piece.suspendMementoNotifications(true);
		
		((Man) piece).move(Movement.getOppositeDirection(direction));
		
		piece.suspendMementoNotifications(false);
	}
	
	/**
	 * @see model.memento.PieceUndoableEdit#redo()
	 */
	@Override
	public void redo() throws CannotRedoException {
		piece.suspendMementoNotifications(true);
		
		((Man) piece).move(direction);
		
		piece.suspendMementoNotifications(false);
	}
}
